{
LANG : PASCAL
PROB : sort3
}

program SORT3;
const
  fi = 'sort3.in';
  fo = 'sort3.out';
  max = 10000;
var
  a : array[1..max] of byte;
  c : array[1..3, 1..3] of longint;
  s : array[1..3] of longint;
  n, sum, p1, p2 : longint;

procedure inp;
var
  i : longint;
begin
  read(n);
  fillchar(s, sizeof(s), 0);
  for i := 1 to n do
  begin
    read(a[i]);
    inc(s[a[i]]);
  end;
  p1 := s[1];
  p2 := s[1] + s[2];
end;

procedure init;
var
  i : longint;
begin
  fillchar(c, sizeof(c), 0);
  for i := 1 to p1 do inc(c[1, a[i]]);
  for i := p1+1 to p2 do inc(c[2, a[i]]);
  for i := p2+1 to n do inc(c[3, a[i]]);
end;

function max2(x, y : longint) : longint;
begin
  if x > y then max2 := x
  else max2 := y;
end;

function min2(x, y : longint) : longint;
begin
  if x > y then min2 := y
  else min2 := x;
end;

function kt : boolean;
var
  i, j : integer;
begin
  for i := 1 to 3 do
    if c[i, i] <> s[i] then
    begin
      kt := false;
      exit;
    end;
  kt := true;
end;

procedure process;
var
  i, j, v : longint;
begin
  sum := 0;
  repeat
    for i := 1 to 3 do
      for j := i+1 to 3 do
      begin
        v := min2(c[i, j], c[j, i]);
        inc(sum , v);
        dec(c[i, j], v);
        dec(c[j, i], v);
        inc(c[i, i], v);
        inc(c[j, j], v);
      end;
    for i := 1 to 3 do
      for j := 1 to 3 do
        if i <> j then
        begin
          v := min2(c[6-i-j, j], c[j, i]);
          inc(sum, v);
          dec(c[6-i-j, j], v);
          dec(c[j, i], v);
          inc(c[j, j], v);
          inc(c[6-i-j, i], v);
        end;
  until kt;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  init;
  process;
  writeln(sum);
  close(input);
  close(output);
end.